package uy.com.tsi2G7.superbet.ui;

import java.util.Date;

import javax.ejb.EJB;
import javax.ejb.ObjectNotFoundException;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import uy.com.tsi2G7.superbet.event.EventService;
import uy.com.tsi2G7.superbet.event.dao.ObjectAlreadyExistsException;

@ManagedBean(name = "eventManagement")
@ViewScoped
public class EventManagement extends AbstractBean{

	@EJB
	private EventService eventService;
	private String marketResultName;
	private long marketResultId;
	private long eventId;
	private long marketId;
	private String eventInputName;
	private String marketInputName;
	private Date marketDate;
	
	public String addMarket(){
		try {
			eventService.addMarket(eventType.getId(), event.getId(),marketInputName,marketId,marketDate);
			getPanelMenuBean().refreshGroups();
		} catch (ObjectNotFoundException e) {
			this.showErrorMessage("Datos Incorrectos");
			e.printStackTrace();
			return null;
		} catch (ObjectAlreadyExistsException e) {
			this.showErrorMessage("El mercado ya existe");
			e.printStackTrace();
			return null;
		}
	
		return "welcome";
		
		
	}
	
	
	public String addEvent(){
		try {
			eventService.addEvent(eventType.getId(), eventId,eventInputName);
			getPanelMenuBean().refreshGroups();
		} catch (ObjectNotFoundException e) {
			this.showErrorMessage("Datos Incorrectos");
			e.printStackTrace();
			return null;
		} catch (ObjectAlreadyExistsException e) {
			this.showErrorMessage("El evento ya existe");
			e.printStackTrace();
			return null;
		}
	
		return "welcome";
		
		
	}
	
	public String addMarketResult() {
		try {
			eventService.addMarketResult(marketResultId,marketResultName,eventType.getId(),event.getId(),market.getId(),amount);
		} catch (ObjectNotFoundException e) {
			this.showErrorMessage("Datos Incorrectos");
			e.printStackTrace();
			return null;
		} catch (ObjectAlreadyExistsException e) {
			this.showErrorMessage("El resultado ya existe");
			e.printStackTrace();
			return null;
		}
	
		return "welcome";
	}

	public String getMarketResultName() {
		return marketResultName;
	}

	public void setMarketResultName(String marketResultName) {
		this.marketResultName = marketResultName;
	}

	public long getMarketResultId() {
		return marketResultId;
	}

	public void setMarketResultId(long marketResultId) {
		this.marketResultId = marketResultId;
	}

	public long getEventId() {
		return eventId;
	}

	public void setEventId(long eventId) {
		this.eventId = eventId;
	}

	public long getMarketId() {
		return marketId;
	}

	public void setMarketId(long marketId) {
		this.marketId = marketId;
	}

	public String getEventInputName() {
		return eventInputName;
	}

	public void setEventInputName(String eventInputName) {
		this.eventInputName = eventInputName;
	}

	public String getMarketInputName() {
		return marketInputName;
	}

	public void setMarketInputName(String marketInputName) {
		this.marketInputName = marketInputName;
	}

	public Date getMarketDate() {
		return marketDate;
	}

	public void setMarketDate(Date marketDate) {
		this.marketDate = marketDate;
	}
	
	
}
